<?php
namespace App\Services;
use App\Models\TeachingAidsModel;

class TeachingAidsService{
    /**
     * 获取教具包信息
     * @return object $aidsInfo
     */
    public function getTaInfo(){
        $aidsInfo = TeachingAidsModel::orderBy('id','desc')->first();
        return $aidsInfo;
    }

	/**
	 * 获取教具包列表
	 * @param int $pagesize;
	 * @param string $keywords
	 * @return object $aidsList
	 */
	public function getTaList($pagesize,$keywords){
		$aidsList = TeachingAidsModel::orderBy('id','desc')
					->where('isshow',1)
					->where(function($query) use ($keywords){
						if($keywords != ''){
							$query->where('name', 'like', '%'.$keywords.'%');
						}
					})
					->select('id','name','num','aid_num','stock','price','add_date')
					->paginate($pagesize);
		return $aidsList;
	}

	/**
	 * 获取教具包详细信息
	 * @param string $name
	 * @return object $aidsInfo
	 */
	public function getTaInfoByName($name){
		$aidsInfo = TeachingAidsModel::where('name',$name)->first();
		return $aidsInfo;
	}

	/**
	 * 获取教具包详细信息
	 * @param int $id
	 * @return object $aidsInfo
	 */
	public function getTaInfoById($id){
		$aidsInfo = TeachingAidsModel::where('id',$id)->first();
		return $aidsInfo;
	}

	/**
	 * 插入教具包
	 * @param array $data
	 * @return $res
	 */
	public function insertTa($data){
		$res = TeachingAidsModel::insert($data);
		return $res;
	}

	/**
	 * 更新教具包
	 * @param int $id
	 * @param array $data
	 * @return bool $res
	 */
	public function modifyTa($id,$data){
		$res = TeachingAidsModel::where('id',$id)->update($data);
		return $res;
	}
}